from unittest import TestCase, main
from pymeter.api.config import (
    TestPlan,
    ThreadGroupSimple,
    ThreadGroupWithRampUpAndHold,
    SetupThreadGroup,
    TeardownThreadGroup,
)
from pymeter.api.samplers import HttpSampler


class TestPlanClass(TestCase):

    @classmethod
    def setUpClass(cls):
        print("setupClass")

    @classmethod
    def tearDownClass(cls):
        print("tearDownClass")

    def test_1(self):
        http_sampler1 = HttpSampler(
            "http_sampler1", "https://postman-echo.com/get?var=1"
        )
        http_sampler2 = HttpSampler(
            "http_sampler2", "https://postman-echo.com/get?var=2"
        )
        http_sampler3 = HttpSampler(
            "http_sampler3", "https://postman-echo.com/get?var=3"
        )
        thread_group_setup = SetupThreadGroup(http_sampler1)
        thread_group_main = ThreadGroupWithRampUpAndHold(10, 1, 10, http_sampler2)
        thread_group_teardown = TeardownThreadGroup(http_sampler3)
        test_plan = TestPlan(
            thread_group_setup, thread_group_main, thread_group_teardown
        )
        stats = test_plan.run()
        self.assert_(
            stats.sample_time_99_percentile_milliseconds <= 2000
        ), f"99th percentile is {stats.sample_time_99_percentile_milliseconds} ms"


if __name__ == "__main__":
    main()
